package com.linewow.xhyy.nihaonew.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.linewow.xhyy.nihaonew.R;
import com.linewow.xhyy.nihaonew.entity.image.SimpleImagesInfo;
import com.linewow.xhyy.nihaonew.model.HttpModel;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by LXR on 2016/9/9.
 *
 */
public class ImagesHorizontalAdapter extends RecyclerView.Adapter<ImagesHorizontalAdapter.ViewHolder> {
    private List<SimpleImagesInfo> list;
    private Context context;
    private LayoutInflater layoutInflater;
    private String TAG="ImagesHorizontalAdapter";

    public ImagesHorizontalAdapter(List<SimpleImagesInfo> list, Context context) {
        this.list = list;
        this.context = context;
        layoutInflater=LayoutInflater.from(context);
    }

    @Override
    public ImagesHorizontalAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=layoutInflater.inflate(R.layout.item_tag_detail_images, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ImagesHorizontalAdapter.ViewHolder holder, int position) {

        if(list.size()<=6){
            SimpleImagesInfo simpleImagesInfo=list.get(position+1);
            Picasso.with(context).load((simpleImagesInfo.image+ HttpModel.IMAGEBIGSUFFIX).replace("m.en1on1.com", "huibenabc.com")).fit().centerCrop().error(R.mipmap.err_topic).into(holder.item1TagDetailImage);
        } else{
            if(position==4){
                    holder.item1TagDetailImage.setImageResource(R.mipmap.icon_continue);
            }else{
                SimpleImagesInfo simpleImagesInfo=list.get(position+1);
                Picasso.with(context).load((simpleImagesInfo.image+HttpModel.IMAGEBIGSUFFIX).replace("m.en1on1.com", "huibenabc.com")).fit().centerCrop().error(R.mipmap.err_topic).into(holder.item1TagDetailImage);
            }
        }



    }

    @Override
    public int getItemCount() {
        if(list.size()==1){
            return  0;
        }else if(list.size()>6){
            return 5;
        }else{
            return list.size()-1;
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.item1_tag_detail_image)
        ImageView item1TagDetailImage;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
